package org.example.mulitithreading.ex8;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.*;

public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        System.out.println("提交任务之前 "+getStringDate());
        Future<String> future = executorService.submit(() -> {
            Thread.sleep(3000);
            System.out.println("called方法执行了");
            return "call方法返回值";
        });
        System.out.println("提交任务之后，获取结果之前 "+getStringDate());
        System.out.println("获取返回值: "+future.get());
        System.out.println("获取到结果之后 "+getStringDate());
        executorService.shutdown();
    }

    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return formatter.format(currentTime);
    }
}
